package com.sakura.mall.order.orderOperateHistory.controller;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.common.response.R;
import com.sakura.mall.order.orderOperateHistory.domain.request.AddOrderOperateHistoryRequest;
import com.sakura.mall.order.orderOperateHistory.domain.request.UpdateOrderOperateHistoryRequest;
import com.sakura.mall.order.orderOperateHistory.domain.request.OrderOperateHistoryPageRequest;
import com.sakura.mall.order.orderOperateHistory.service.OrderOperateHistoryService;
import com.sakura.mall.order.orderOperateHistory.domain.vo.OrderOperateHistoryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 订单操作历史记录
 *
 * @author sakura
 */
@RestController
@RequestMapping("/orderOperateHistory")
@RequiredArgsConstructor
public class OrderOperateHistoryController {

    private final OrderOperateHistoryService orderOperateHistoryService;


    /**
     * 新建
     *
     * @return R {@link Void}
     */
    @PostMapping
    public R<Void> create(@RequestBody @Validated AddOrderOperateHistoryRequest request) {
        orderOperateHistoryService.add(request);
        return R.ok();
    }


    /**
     * 分页获取
     *
     * @return R {@link Page<OrderOperateHistoryVo>}
     */
    @GetMapping("list")
    public R<Page<OrderOperateHistoryVo>> page(OrderOperateHistoryPageRequest request) {
        Page<OrderOperateHistoryVo> ret = orderOperateHistoryService.queryPage(request);
        return R.ok(ret);
    }


    /**
     * 根据id删除
     *
     * @return R {@link Void}
     */
    @DeleteMapping("{id}")
    public R<Void> remove(@PathVariable Long id) {
        orderOperateHistoryService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id更新
     *
     * @return R {@link Void}
     */
    @PostMapping("{id}")
    public R<Void> update(@PathVariable Long id, @RequestBody UpdateOrderOperateHistoryRequest request) {
        orderOperateHistoryService.updateById(id, request);
        return R.ok();
    }

}
